package fag.core.game.test.pong;

import fag.core.game.StandardDoodad;
import fag.core.geometry.Vector2D;
import fag.core.model.Model;

public class Ball extends StandardDoodad {
	
	private Vector2D speed;
	
	public Ball(Model model, Vector2D speed) {
		super(model);
		this.speed = speed;
	}
	
	public void bounce(Vector2D normal) {
		speed.set(speed.add(normal.mul(normal.dot(speed.mul(-1)) * 2)));
	}
	
	public void step(double dt) {
		translate(speed.x * dt, speed.y * dt, Referential.ABSOLUTE);
		double angle = Math.atan(-speed.y / speed.x);
		if(speed.x < 0.0) {
			angle = angle + Math.PI;
		}
		speed.set(speed.add(new Vector2D(Math.cos(angle)*0.05,-Math.sin(angle)*0.05)));
	}
}
